﻿
@{ 
}
<div id="tb">
    <div class="t-toolbar">
        <a id="a_refresh" href="#" plain="true" class="easyui-linkbutton" icon="fa fa-refresh" title="刷新" onClick="refreshClick()">刷新</a>
        <a id="a_add" href="#" plain="true" class="easyui-linkbutton" icon="fa fa-plus" title="新增" onClick="addClick()">新增</a>
        <a id="a_edit" href="#" plain="true" class="easyui-linkbutton" icon="fa fa-pencil" title="编辑" onClick="editClick()">编辑</a>
        <a id="a_del" href="#" plain="true" class="easyui-linkbutton" icon="fa fa-times" title="删除" onClick="deleteClick()">删除</a>
    </div>
</div>
<table id="tg" style="width:600px;height:400px"></table>
<script type="text/javascript">
    $(document).ready(function () {
        $('#tg').treegrid({
            title: '菜单管理',
            url: '/sys/menu/Indexajax',
            method: 'get',
            idField: 'menu_id',
            treeField: 'name',
            toolbar: "#tb",
            columns: [[
                { title: '菜单名', field: 'name', width: 180 },
                { title: '图标', field: 'iconCls', width: 60, align: 'right' },
                { title: '链接', field: 'url', width: 80 },
                { title: '排序', field: 'sort', width: 80 },
            ]],
            onDblClickRow: function (row) {
                showEditWin(row.menu_id);
            }
        });
    });
    // 刷新
    function refreshClick() {
        $('#tg').treegrid('load');
    }
    // 添加
    function addClick() {
        showEditWin(0);
    }
    // 编辑
    function editClick() {
        var node = $('#tg').treegrid('getSelected');
        if (node) {
            showEditWin(node.menu_id);
        } else {
            sx.info("请选择一条数据！");
        }
    }
    function showEditWin(id) {
        sx.win({
            content: "/sys/menu/edit?id=" + id,
            data: {}
        }, function (data) { 
            $('#tg').treegrid('reload');
        });
    }
    function deleteClick() {
        var node = $('#tg').treegrid('getSelected');
        if (node) {
            $.ajax({
                type: "post",
                url: "/sys/menu/delete",
                data: { id: node.menu_id },
                dataType: "json",
                success: function (r) {
                    if (r.success) {
                        sx.success("删除成功！", function () {
                            refreshClick();
                        });
                    } else {
                        sx.error(r.info);
                    }
                }
            });
        } else {
            sx.info("请选择一条数据！");
        }
    }
</script> 